﻿package org.lively3d.objects.special {
	import org.cairngorm.model.ViewModelLocator;
	import org.papervision3d.core.geom.Particles;
	import org.papervision3d.core.geom.renderables.Particle;
	import org.papervision3d.materials.special.ParticleMaterial;
	/**
	 * @Author Ralph Hauwert modified by Lively
	 */
	 
	public class SkyMap extends Particles
	{
		
		private var skyRadius:Number;
		/* private var fieldHeight:Number;
		private var fieldWidth:Number; */
		private var quantity:int;		
		private var color:int;
		
		//Add Livevly Cairngorm
		private var modelLocator:ViewModelLocator=ViewModelLocator.getInstance();
		
		/**
		* The ParticleField class creates an object with an amount of particles randomly distributed over a specied 3d area.
		* @param	material 	The Material for the to be created particles
		* @param	color		The color of the created particles
		* @param	container	An alternate container to render to, if needed.
		* @param	fieldWidth 	The width of the area
		* @param 	fieldHeight The height of the area
		* @param	fieldDepth	The depth of the area 
		*/
		public function SkyMap(mat:ParticleMaterial, quantity:int = 200, particleSize:Number=4, skyRadius:Number = 2000)
		{
			super("ParticleField");
			
			this.material = mat;
			this.quantity = quantity;
			
			this.skyRadius = skyRadius;
			/* this.fieldHeight = fieldHeight;
			this.fieldDepth = fieldDepth; */
			
			createParticles(particleSize);
		}
		
		private function createParticles(size:Number):void
		{
			/* var width2  :Number = fieldWidth /2;
			var height2 :Number = fieldHeight /2;
			var depth2  :Number = fieldDepth /2; */
			var c:int;
			var r:int;
			
			//Lively Modifications Add Particle Stuff
			//Spherical equations
			/*
			x = r*cos(2*Math.PI*rac/24)sin(Dec*Math.PI/180);
			y = r*sin(2*Math.PI*rac/24)sin(Dec*Math.PI/180);
			z = r*cos(Dec*Math.PI/180);
			
			*/
			
			
			var myPartNum:Number = modelLocator.myStarData.length/4;
			for( var i:Number = 0; i < myPartNum; i++ )
			{
				
				/* var myX:Number=skyRadius*(Math.cos(2*Math.PI*modelLocator.myStarData[4*i]/24)*Math.sin((90-modelLocator.myStarData[4*i+1])*Math.PI/180));
				var myZ:Number=-skyRadius*(Math.sin(2*Math.PI*modelLocator.myStarData[4*i]/24)*Math.sin((90-modelLocator.myStarData[4*i+1])*Math.PI/180));
				var myY:Number=skyRadius*Math.cos((90-modelLocator.myStarData[4*i+1])*Math.PI/180) */
				
				
				var myX:Number=skyRadius*(Math.cos(2*Math.PI*modelLocator.myStarData[4*i]/24)*Math.sin((90-modelLocator.myStarData[4*i+1])*Math.PI/180));
				var myZ:Number=-skyRadius*(Math.sin(2*Math.PI*modelLocator.myStarData[4*i]/24)*Math.sin((90-modelLocator.myStarData[4*i+1])*Math.PI/180));
				var myY:Number=skyRadius*Math.cos((90-modelLocator.myStarData[4*i+1])*Math.PI/180)
				
				
				
				
				var mySize:Number=size*(3-modelLocator.myStarData[(4*i+3)]);
				
				addParticle(new Particle(material as ParticleMaterial, mySize, myX, myY, myZ));
			}
		}
		
	}
}